const telReg = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/; //电话号码
const nameReg = /^[\u4e00-\u9fa5]{2,4}$/; //2到4个中文字符
const emailReg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; //邮箱
const qqReg = /^[1-9][0-9]\d{4,9}$/; //qq号码
const codeReg = /^[1-9][0-9]\d{4,9}$/; //邮政编码
const regReg = /^[a-zA-Z][a-zA-Z0-9_]{4,15}$/; //注册号码
const chineseReg=/^[\u4e00-\u9fa5]+$/; //匹配汉字
const chineseChatReg=/^[a-zA-Z0-9\u4e00-\u9fa5-_]+$/; //匹配汉字和字符

//匹配密码，以字母开头，长度在6-12之间，只能包含字符、数字和下划线。
const isPwd = function(str) {
	if (str == null || str == "") return false;
	var result = str.match(/^[a-zA-Z]\\w{6,12}$/);
	if (result == null) return false;
	return true;
}
/**
 * 匹配身份证号码
 */
function isIdCardNo(num) {
	var len = num.length,
		reg;
	if (len == 15)
		reg = new RegExp(/^(\d{6})()?(\d{2})(\d{2})(\d{2})(\d{2})(\w)$/);
	else if (len == 18)
		reg = new RegExp(/^(\d{6})()?(\d{4})(\d{2})(\d{2})(\d{3})(\w)$/);
	else {
		return {
			state: false,
			message: '输入的身份证号长度不对'
		};
	}
	var a = num.match(reg);
	if (a != null) {
		if (len == 15) {
			var D = new Date("19" + a[3] + "/" + a[4] + "/" + a[5]);
			var B = D.getYear() == a[3] && (D.getMonth() + 1) == a[4] && D.getDate() == a[5];
		} else {
			var D = new Date(a[3] + "/" + a[4] + "/" + a[5]);
			var B = D.getFullYear() == a[3] && (D.getMonth() + 1) == a[4] && D.getDate() == a[5];
		}
		if (!B) {
			return {
				state: false,
				message: "输入的身份证号 " + a[0] + " 里出生日期不对。"
			};
		}
	}
	if (!reg.test(num)) {
		return {
			state: false,
			message: '身份证最后一位只能是数字和字母'
		};
	}

	return {
		state: true
	};
}
module.exports = {
	telReg,
	isPwd
}
